<?php
namespace app\index\controller;
use think\Controller;
use app\index\controller\Base;
use think\Request;
use think\Db;
class Links extends Base
{
	//判断是否是POST请求
	public function ispost(){
		if (!Request::instance()->isPost()){
			$this->redirect('index');
		}
	}

    public function index()
    {
    	$base = new Base();
    	$base->bloginfo();
    	$links = db('links')->where('hidder', '=', 0)->order('num','dec')->select();
    	$this->assign('links',$links);
    	return $this->fetch('./index/link');
    }
    public function linkadd(){
    	$this->ispost();
    	$data = [
            'name' => input('urlname'),
            'url'  => input('url'),
            'hidder' => 1,
            'email' => input('email'),
            '__token__'=> input('__token__')
        ];
        $validate = new \app\index\validate\LinkPost;
        if (!$validate->check($data)) {
            $data = ["result"=>2, "msg"=>"请不要重复提交"];
            echo json_encode($data);
        }else{
            Db::name('links')->strict(false)->insert($data);
            $data = ["result"=>1, "msg"=>"提交成功，请等待管理员审核。"];
            echo json_encode($data);
        }
       
    }
}
